<template>
	<view class="set-pwd">
		<!--师傅  设置密码 -->
		<u-navbar leftIconSize="34rpx" autoBack :placeholder="true" bgColor="#ffffff">
			<view class="" slot="center">
				<text class="c-000 pf-sc fw-600" style="font-size: 34rpx;">修改登录密码</text>
			</view>
		</u-navbar>
		<view
			class="set-pwd-container w-750 b-box  bg-ff po-re"
			style="padding: 20rpx 74rpx;"
			:style="{ height: containerHeight }"
		>
			<view class="w-100 b-box" style="margin-bottom: 60rpx;">
				<view
					class="flex-c ali-i-s just-s"
					style="padding-bottom: 34rpx;margin-top: 44rpx;border-bottom: 2rpx solid #F1F1F1;"
				>
					<u-input
						border="none"
						placeholder="请输入原登录密码"
						:customStyle="{ color: '#222222', font: '400 30rpx PingFang SC' }"
						placeholderStyle="color:#bfbfbf;fontWeight:400;fontsize:30px;fontfamily:PingFang SC-Regular, PingFang SC}"
						v-model="requetParams.oldPwd"
					></u-input>
				</view>
				<view
					class="flex-c ali-i-s just-s po-re"
					style="padding-bottom: 34rpx;margin-top: 44rpx;border-bottom: 2rpx solid #F1F1F1;"
				>
					<u-input
						border="none"
						placeholder="请设置新登录密码"
						:password="showPwd1"
						:customStyle="{
							boxSizing: 'border-box',
							paddingRight: '60rpx',
							color: '#333333',
							font: '400 30rpx PingFang SC'
						}"
						placeholderStyle="color:#bfbfbf;fontWeight:400;fontsize:30px;fontfamily:PingFang SC-Regular, PingFang SC}"
						v-model="requetParams.newPwd"
					></u-input>
					<view class="po-ab" style="right: 0;top:5rpx">
						<image
							v-if="showPwd1"
							@click="ShowPwd(1)"
							:src="require('../static/showpwd.png')"
							style="width: 40rpx;height: 24rpx;"
							mode=""
						></image>
						<image
							v-else
							@click="ShowPwd(1)"
							:src="require('../static/hidepwd.png')"
							style="width: 40rpx;height: 24rpx;"
							mode=""
						></image>
					</view>
				</view>
				<view
					class="flex-c ali-i-s just-s po-re"
					style="padding-bottom: 34rpx;margin-top: 44rpx;border-bottom: 2rpx solid #F1F1F1;"
				>
					<u-input
						border="none"
						placeholder="再次输入新登录密码"
						:password="showPwd2"
						:customStyle="{
							boxSizing: 'border-box',
							paddingRight: '60rpx',
							color: '#333333',
							font: '400 30rpx PingFang SC'
						}"
						placeholderStyle="color:#bfbfbf;fontWeight:400;fontsize:30px;fontfamily:PingFang SC-Regular, PingFang SC}"
						v-model="requetParams.renewPwd"
					></u-input>
					<view class="po-ab" style="right: 0;top:5rpx">
						<image
							v-if="showPwd2"
							@click="ShowPwd(2)"
							:src="require('../static/showpwd.png')"
							style="width: 40rpx;height: 24rpx;"
							mode=""
						></image>
						<image
							v-else
							@click="ShowPwd(2)"
							:src="require('../static/hidepwd.png')"
							style="width: 40rpx;height: 24rpx;"
							mode=""
						></image>
					</view>
				</view>
			</view>
			<!--  -->
			<view class="w-100 b-box  d-flex flex-r ali-i-c just-c">
				<u-button
					:throttleTime="700"
					@click="Submit"
					:customStyle="{
						height: '88rpx',
						width: '602rpx',
						font: '400 32rpx PingFang SC',
						color: '#ffffff',
						borderWidth: '0rpx',
						background: 'linear-gradient(180deg, #4885C5 0%, #3B52A6 100%)',
						borderRadius: '44rpx'
					}"
					shape="square"
					text="确定"
				></u-button>
			</view>
		</view>
	</view>
</template>

<script>
import {changepwd} from '@/common/api.js';
import { _containerHeight } from '@/utils/GetSys.js';
import Unavbar from '../components/uview-ui/components/u-navbar/u-navbar';
import Uinput from '../components/uview-ui/components/u-input/u-input';
import Ubutton from '../components/uview-ui/components/u-button/u-button';
export default {
	components: {
		'u-navbar': Unavbar,
		'u-input': Uinput,
		'u-button': Ubutton
	},
	data() {
		return {
			containerHeight: '',
			showPwd1: true,
			showPwd2: true,
			requetParams: {
				oldPwd: '',
				newPwd: '',
				renewPwd:''
			}
		};
	},
	methods: {
		ShowPwd(index) {
			this[`showPwd${index}`] = !this[`showPwd${index}`];
		},
		Submit() {
			// uni.navigateBack({
			// 	delta: 1
			// });
			if(this.requetParams.oldPwd==''){
				uni.showToast({
					title:'原密码不能为空',
					icon:'none'
				})
				return
			}
			if(this.requetParams.newPwd==''){
				uni.showToast({
					title:'新密码不能为空',
					icon:'none'
				})
				return
			}
			if(this.requetParams.renewPwd==''){
				uni.showToast({
					title:'新密码不能为空',
					icon:'none'
				})
				return
			}
			if(this.requetParams.newPwd != this.requetParams.renewPwd){
				uni.showToast({
					title:'两次输入的密码不一致',
					icon:'none'
				})
				return
			}
			let params={
				token:uni.getStorageSync('user').token,
				newpassword:this.requetParams.newPwd,//新密码
				npassword:this.requetParams.renewPwd,//确认密码
				oldpassword:this.requetParams.oldPwd
			}
			changepwd(params).then((res)=>{
				if(res.data.code==1){
					uni.switchTab({
						url:'/pages/UserCenter/UserCenter'
					})
					uni.showToast({
						title:'密码修改成功',
						icon:'none'
					})
				}
			})
		}
	},
	onLoad() {
		this.containerHeight = _containerHeight();
	}
};
</script>

<style lang="scss">
.set-pwd {
}
</style>
